package com.lych.server.controller;

import com.lych.model.vo.PageResult;
import com.lych.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 分页查询评论列表
     * @param movementId
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    public ResponseEntity findComments(String movementId,
                                       @RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = commentService.findComments(movementId, page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 评论-提交
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map map){
        commentService.saveComments(map);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论点赞
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity idLike(@PathVariable("id") String commentId){
        Integer idLikeCount = commentService.idLike(commentId);
        return ResponseEntity.ok(idLikeCount);
    }

    /**
     * 取消评论点赞
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity idDisLike(@PathVariable("id") String commentId){
        Integer idDisLikeCount = commentService.idDisLike(commentId);
        return ResponseEntity.ok(idDisLikeCount);
    }
}
